#include "StdAfx.h"
#include "VideoFileCam.h"


CVideoFileCam::CVideoFileCam(const char* videoFile)
{
    if (videoFile == NULL)
    {
        throw "videoFile name is null";
    }

    int len = strlen(videoFile)+1;
    this->pFile = new char[len];
    strcpy_s(this->pFile, len, videoFile);

    this->pCapturer = NULL;
}


CVideoFileCam::~CVideoFileCam(void)
{
    if (this->pCapturer != NULL)
    {
        cvReleaseCapture(&this->pCapturer);
        this->pCapturer = NULL;
    }

}

void CVideoFileCam::Initialize()
{
    if (this->pCapturer == NULL)
    {
        this->pCapturer = cvCaptureFromAVI(this->pFile);
        if (this->pCapturer == NULL)
        {
            throw CString("file can't be opened");
        }
    }

    m_initialized = true;
}

IplImage* CVideoFileCam::CaptureFrame()
{
    if (this->pCapturer == NULL)
    {
        throw "not initialized";
    }

    IplImage* image = cvQueryFrame(this->pCapturer);
    return image;

}
